import 'package:flutter/material.dart';
import 'package:shenling/pages/my/components/options.dart';
import 'package:shenling/utils/token.dart';

class SettingPage extends StatefulWidget {
  const SettingPage({super.key});

  @override
  State<SettingPage> createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  showConfirmDialog() {
    return showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
              title: const Text('温馨提示'),
              content: const Text('确定要退出登录吗？'),
              actions: [
                TextButton(
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    child: const Text(
                      '取消',
                      style: TextStyle(color: Colors.red),
                    )),
                TextButton(
                    onPressed: () {
                      // print('确定退出登录');
                      TokenManager().removeToken();
                      Navigator.pop(context);
                      Navigator.pushNamedAndRemoveUntil(
                          context, '/login', (route) => false);
                    },
                    child: const Text('确定'))
              ]);
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          title: const Text('系统设置'),
          centerTitle: true,
        ),
        body: // 选项
            Column(
          children: [
            Padding(
              padding: const EdgeInsets.only(top: 20, left: 20, right: 20),
              child: Container(
                // width: MediaQuery.of(context).size.width,
                height: 280,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.grey.withOpacity(0.5),
                      spreadRadius: 5,
                      blurRadius: 7,
                      offset: const Offset(0, 3), // changes position of shadow
                    ),
                  ],
                ),
                child: ListView(
                  children: [
                    // -------------- 换绑手机 -----------------
                    const SizedBox(height: 15),
                    OptionsView(title: '换绑手机'),
                    const SizedBox(height: 15),
                    // 分割线
                    const Divider(
                      height: 1,
                      color: Color.fromARGB(255, 236, 234, 234),
                      indent: 20,
                      endIndent: 20,
                      // 宽度
                    ),
                    // -------------- 修改密码 -----------------
                    const SizedBox(height: 15),
                    OptionsView(title: '修改密码'),
                    const SizedBox(height: 15),
                    // 分割线
                    const Divider(
                      height: 1,
                      color: Color.fromARGB(255, 236, 234, 234),
                      indent: 20,
                      endIndent: 20,
                      // 宽度
                    ),
                    // -------------- 消息通知设置 -----------------
                    const SizedBox(height: 15),
                    OptionsView(title: '消息通知设置'),
                    const SizedBox(height: 15),
                    // 分割线
                    const Divider(
                      height: 1,
                      color: Color.fromARGB(255, 236, 234, 234),
                      indent: 20,
                      endIndent: 20,
                      // 宽度
                    ),
                    // ----------------- 修改密码 ---------------
                    const SizedBox(height: 15),
                    OptionsView(title: '修改密码'),
                    const SizedBox(height: 15),
                    // 分割线
                    const Divider(
                      height: 1,
                      color: Color.fromARGB(255, 236, 234, 234),
                      indent: 20,
                      endIndent: 20,
                      // 宽度
                    ),
                    // ----------------- 清理缓存 ---------------
                    const SizedBox(height: 15),
                    OptionsView(title: '清理缓存'),
                    const SizedBox(height: 15),
                  ],
                ),
              ),
            ),
            Padding(
                padding: const EdgeInsets.only(top: 20, left: 20, right: 20),
                child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: 60,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(10),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.grey.withOpacity(0.5),
                            spreadRadius: 5,
                            blurRadius: 7,
                            offset: const Offset(
                                0, 3), // changes position of shadow
                          ),
                        ]),
                    child: TextButton(
                        onPressed: () {
                          showConfirmDialog();
                        },
                        child: const Text('退出登录',
                            style:
                                TextStyle(color: Colors.red, fontSize: 16)))))
          ],
        ));
  }
}
